﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Rhino.Mocks;

namespace SeleniumToolkit.Core
{
    public class SessionInfoHelperSpecs : ContextSpecification
    {
        ISessionInfo info;

        protected override void Context()
        {
            info = MockRepository.GenerateStub<ISessionInfo>();
        }

        [TestFixture]
        public class WhenCopyingAttributesFromDecoratedTypeToEmptySessionInfo : SessionInfoHelperSpecs
        {

            protected override void Because()
            {
                SessionInfoHelper.CopyAttributes(info, typeof(ExampleFixtureWithTypeAttributes));
            }

            [Test]
            public void ShouldHaveBaseUrl()
            {
                info.BaseUrl.ShouldEqual("http://www.amazon.com");
            }

            [Test]
            public void ShouldHaveTimeout()
            {
                info.Timeout.ShouldEqual("30000");
            }

            [Test]
            public void ShouldHaveDefaultBrowser()
            {
                info.DefaultBrowser.ShouldEqual("*firefox");
            }
        }

        [TestFixture]
        public class WhenCopyingAttributesFromEmptyTypeToExistingSessionInfo : SessionInfoHelperSpecs
        {
            protected override void Context()
            {
                base.Context();
                info.BaseUrl = "http://www.bryancook.net";
                info.DefaultBrowser = "*chrome";
                info.Timeout = "100";
            }

            protected override void Because()
            {
                SessionInfoHelper.CopyAttributes(info, typeof(ExampleFixtureWithNoAttributes));
            }

            [Test]
            public void ShouldHaveOriginalBaseUrlValue()
            {
                info.BaseUrl.ShouldEqual("http://www.bryancook.net");
            }

            [Test]
            public void ShouldHaveOriginalBrowserValue()
            {
                info.DefaultBrowser.ShouldEqual("*chrome");
            }

            [Test]
            public void ShouldHaveOriginalTimeoutValue()
            {
                info.Timeout.ShouldEqual("100");
            }
        }


        [WebFixture(BaseUrl="http://www.amazon.com", DefaultBrowser = "*firefox", Timeout = 30000)]
        class ExampleFixtureWithTypeAttributes
        {
        }

        [WebFixture]
        class ExampleFixtureWithNoAttributes
        {
        }
    }
}
